// components/scroll-row-module/index.ts
const app = getApp();
const hideScrollBar = require("../../behavior/hide-scroll-bar");
import { preparePullLiveStream } from '../../api/index';
const videoIntersectionObserver = require("../../behavior/videoIntersectionObserver")
Component({
  /**
   * 组件的属性列表
   */
  behaviors: [hideScrollBar, videoIntersectionObserver],
  properties: {
    moduleData: {
      type: Object,
      value: {
        title: "标题名称",
        list: []
      }
    },
    itemWidth: {
      type: String,
      value: `${(app.globalData.windowWidth - 10) / 2 - 5}px`
    },
    itemHeight: {
      type: String,
      value: `${((app.globalData.windowWidth - 10) / 2 - 5) * 9 / 16}px`
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    windowWidth: app.globalData.windowWidth
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tapCardItem(event) {
      app.globalData.currentPlayVideoID = event.currentTarget.dataset.code;
      app.globalData.currentPlayElv = event.currentTarget.dataset.elvname;
      app.globalData.CameraOrigin = event.currentTarget.dataset.cameraorigin;
      app.globalData.currentEnterPriseID = event.currentTarget.dataset.enterpriseid;

      let title = event.currentTarget.dataset.title
      const pages = getCurrentPages()
      let currentPage = pages[pages.length - 1]

      wx.navigateTo({
        url: `/pages/play-page/index?title=${title}`
      })
      // if (currentPage.route == "pages/enterprise/views/home/index" && this.properties.moduleData.title !== "企业直播") {
      //   wx.navigateBack()
      // } else {
      //   wx.navigateTo({
      //     url: `/pages/play-page/index?title=${title}`
      //   })
      // }

    },
    goToMorePage() {
      wx.navigateTo({
        url: `/pages/more-page/index?pageTitle=${this.properties.moduleData.title}`
      })
    },
  },
  observers: {
    moduleData(val) {
      if (val && val.list.length > 0) {
        this.observe((res) => {
          // console.log('监听成功', res);
          let value = res.dataset.value
          if (value.code && value.elvName && app.globalData.token) {
            preparePullLiveStream({
              CamID: value.code,
              ELVName: value.elvName
            })
          }
        }, ".video-item")
      }
    }
  }
})
export { }